import unittest
import requests


class TpLogin:
    se = None

    @classmethod
    def __login_v(cls):
        if cls.se is None:
            url_v = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify"
            cls.se = requests.Session()
            cls.se.get(url_v)
        return cls.se

    @classmethod
    def login_ok(cls, login_data):
        cls.__login_v()
        url_lo = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        rse = cls.se.post(url_lo, data=login_data)
        cls.__free_session()
        return rse

    @classmethod
    def __free_session(cls):
        if cls.se:
            cls.se.close()
            cls.se = None
